<%@ page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@page import="com.ufida.ebscg.comm.Constant" %>
<html>
<head>
		<title>
		供货量上报
		</title>
	<link href="../css/style.css" rel="stylesheet" type="text/css" />
	<link href="../css/style_add.css" rel="stylesheet" type="text/css" />
<link href="css/collcss.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="../javascript/caltimer.js"></script>
<script language="JavaScript" type="text/javascript" src="../javascript/ajaxdeal.js"></script>
</head>

<body>

<div style="margin-left:30px">
 <form action="supplierfile.do"  enctype="MULTIPART/FORM-DATA" method ="post" name="insertPriceItemForm" id="fileupload">
		<div style="width:100%">
			
				项目名称:<input type="text" id="projname" width="120px"  style="height:22px" disabled value="${projname }" /><img src="../images/ref_on.gif" style="cursor:hand" onclick="showProjectMes()"></img>
				上报名称:<input type="text" width="120px" name="report_name" id="report_name"  style="height:22px" value="${report_name}"/>
				<input type="hidden" name="projid" id="projid" value="${projid}"/>
				<input type="hidden" name="projname" id="projnamehidden"  value="${projname }"/>
				<input type="button" value="查&nbsp;&nbsp;询" style="height:22px" onclick="queryFile()"/>
		</div>
		
		<div>
		
				<table width="610" border="0" cellpadding="0" cellspacing="0" height="120" class="xian"  >
    <tr>
      <td valign="middle">
   <table width="610" border="0" cellpadding="0" cellspacing="0" id="fileuploadtable" style="font-size:12">
      <tr>
      <td height="25" align="left" class="f-13-b-2a6ca7" >附件</td>
      <td height="25" class="f-13-b-2a6ca7" >&nbsp;</td>
      <td height="25" class="f-13-b-2a6ca7" >&nbsp;</td>
      <td height="25" colspan="2" class="f-13-b-2a6ca7" >&nbsp;</td>
      </tr>
      <tr class="th_bj">
            <td width="50" height="28" align="center" class="f-12-b-ffffff"  >序</td>
            <td width="200px" height="28" align="center"  ><span class="f-12-b-ffffff" >文件名称</span></td>
             <td width="300px" height="28" align="center" class="f-12-b-ffffff"  >说明</td>
            <td align="right" width='1px'></td>
            <td height="28" width = 160px; align="center" class="f-12-b-ffffff"  ><img src="../images/botton_add.jpg"  border="0" onclick = "addRow()"  style="cursor:hand"/></td>
      </tr>
      </table>
      </td>
    </tr>
  </table>
		
		</div>
		
	
		<p>&nbsp;</p>

	 <table width="610" border="0" cellpadding="0" cellspacing="0" >
	   <tr>
	      <td height="26" align="left" class="f-13-b-2a6ca7" colspan='2'>已上传附件</td>
	 
	    </tr>
	    
	    <tr class="th_bj">
	      <td width="20px"  height="28" align="center" class="f-12-b-ffffff" width="10px" >序</td>
	      <td  width="220px" height="28" align="center" width="200px"><span class="f-12-b-ffffff">文件名称</span></td>
	      <td  width="320px" height="28" align="center" width="300px"><span class="f-12-b-ffffff">说明</span></td>
	      <td  width="80px" height="28" align="center" width="80px"><span class="f-12-b-ffffff">下载</span></td>
	    </tr>
	   
	   <logic:iterate id="att" name="atts" >
	    <tr style="font-size:12px;height:30px">
	     	<td>${att.index}</td>
	     	<td align="center">${att.filename}</td>
	     	<td>${att.memo}</td>
	     	<td align="center"><a href="supplierfile.do?type=6&pk_da_att=${att.pk_da_att}" >下载</a></td>
	    </tr>
	    </logic:iterate>
	    
	  
	  </table> 
	  
	  <span>&nbsp;</span>
	  
	   <div align="center" style="width:610px">
   		 <img src="../images/botton_submit.jpg" width="60"  style="cursor:hand" height="20" border="0" onclick="submitValue()"/>
   	   </div>
	  
</form>	

	  <%if(Constant.CAOPEN){ %>
<OBJECT id="CertSignAtl"  height="0" hspace="0" width="0" align="center" classid="clsid:4FEA81CE-00EA-4FB2-850E-353C947B7A66" VIEWASTEXT>
</OBJECT>  
<%} %>
<TEXTAREA id="certtxt" name="certtxt" rows="17" cols="48"  style="display: none" >${cert}</TEXTAREA>
</div>
	  <script language="vbscript" >


		sub upfileSign(fileobject,index)

			Dim strP7Env
			Dim strSignature
			Dim strCert
			Dim ret
            Dim filepath

            filepath = fileobject.value
			ret = 0 rem ret 必须赋初值
			
			

		   	if IsNull(CertSignAtl) then
					Alert("请确认您是否有权限上载文件")
					return
			end if

			     CertSignAtl.P7EncryptAndSignFile ret,certtxt.value,filepath,strP7Env,strSignature

			     If ret = 0 Then
				       call ondatachange(fileobject,index,strSignature,strP7Env)
				  
			     ElseIf ret = 100 Then
				       deleteRow(index)
			     Else
				     Alert("Error"+ret)
					deleteRow(index)
			     End If
           

		end sub

</script>
<script language="javascript">

var message = "${message}";
if(message != ""){
	parent.showHideFun();
	parent.changeShowMessage(message,'yes','ok');	
}
	var rowindex = 0;
//向批量上传文件的列表中添加一行数据
function addRow()
{
     var root = document.all("fileuploadtable")
     var row = root.insertRow();
     
     row.style.height = '26px';
     rowindex++;
     row.id = "row"+rowindex;
     var cell1 = row.insertCell();
     
     cell1.align="center";
     cell1.innerText = rowindex;
     var cell2 = row.insertCell();
     
     cell2.align="center";
     

     
     var cell3 = row.insertCell();
     
     cell3.innerHTML = "<TEXTAREA  cols='30' rows='3' name='memo'/>";
	
	 var cell4= row.insertCell();
     
    
     var eventHandle = "ondatachange(this,"+rowindex+")";
    
    	
     var innercontent = "<input type='file'  name='inputfile"+rowindex+"' id='file"+rowindex+"' style='position:absolute;opacity:0;filter:alpha(opacity=0); width:20px; height:20px' onchange='"+eventHandle+"' />";

     cell4.innerHTML = innercontent

     cell3 = row.insertCell();
     
      
     cell3.align="center";
     
     var img = "<input type='hidden' name = 'filename' id='filename"+rowindex+"'  /><input type='hidden' name='signfile' id='signfile"+rowindex+"'/><img src='../images/botton_upload-.jpg' id='img"+rowindex+"' style='cursor:hand' border=0 style='cursor:hand'  onmouseover='showfiledialog("+rowindex+")'/>&nbsp<img src='../images/botton_delete.jpg' style='cursor:hand' border=0 style='cursor:hand' onclick='deleteRow("+rowindex+")'/>";
     cell3.innerHTML = img;  
     
}


//删除上传文件
function deleteRow(index)
{
	var root = document.all("fileuploadtable");
	var row = "row"+index ;
	
	var rows = root.rows;
    var deletepos = 0;
    
    
    //寻找到对应的删除行并进行删除
	for(var pos = 0; pos < rows.length; pos++)
	{
		var temprow = rows[pos];
		if(temprow.id == row)
		{
			root.deleteRow(pos);
			deletepos = pos;
			rowindex--;
			break;
		}
	}
	
	
	//当删除行操作时更新显示索引
	for(var pos = deletepos; pos < rows.length; pos++)
	{
		var temprow = rows[pos];
		var cells = temprow.cells;
		
		var cell = cells[0];
		
		if(typeof(cell) == 'object')
		{
			cell.innerText = deletepos-1;
			deletepos++;
		}
	}	

}

//显示项目参照
function showProjectMes(){

	var proj = new projRef();
	window.showModalDialog("supplierfile.do?type=4&rand="+Math.random(),proj,"dialogWidth:400px;dialogHeight:300px");
}


function projRef(){
};


projRef.prototype.setName = function(name){
	
	document.getElementById("projname").value = name;
	document.getElementById("projnamehidden").value = name;
};

projRef.prototype.setId = function(id){

	document.getElementById("projid").value = id;
};
	
/*
*提交数据
*/
function submitValue(){

	if(isEmptyFile())
	{
		var projid = document.getElementById("projid").value;
		var report_name = document.getElementById("report_name").value;
		
		if(projid==""){
		
			showmess("请选择项目!");
			return;
		}
		
		if(report_name == ""){
		
			showmess("请填写上报名称");
			document.getElementById("report_name").focus();
			return;
		}
		var projname = document.getElementById("projname").value;
		
		var url = "supplierfile.do?type=5&rand="+Math.random()+"&projid="+projid+"&report_name="+report_name;
		ajax(url,returnFun);
	}
	
}

/*
*判断上报名称是否唯一
*/
function returnFun(data){

	if(data == "no"){
		document.getElementById("fileupload").action = "supplierfile.do?type=3";
		document.getElementById("fileupload").submit();
	}else{
		
		showmess("上报名称已存在,请更改上报名称!");
	}
}

/**
查询附件信息
*/
function queryFile(){

	
	var projid = document.getElementById("projid").value;
	var report_name = document.getElementById("report_name").value;
	var projname = document.getElementById("projname").value;
	
	if(projid == "" && report_name == ""){
		
		showmess("采购方案或上报名称必须填写一项!");
		return;
	}
	document.getElementById("fileupload").action = "supplierfile.do?type=2";
	document.getElementById("fileupload").submit();
}
/**
判断文件是否存在上传文件
*/
function isEmptyFile(){

	var inputfiles = new Array();
	
	var filestag = document.getElementsByTagName("input");
	
	
	if(typeof(filestag) != "undefined" && filestag != null){
	
		if(typeof(filestag.length) != "undefined"){
			for(var index=0; index<filestag.length; index++){
			
				var file = filestag[index];
				
				if(file.type == "file"){
				
					inputfiles.push(file);
				
				}
			}
		}
	}
	if(inputfiles == null || inputfiles.length == 0){
	
			showmess("请添加文件!");
			return false;
	}else{
	
	
		for(var index=0; index<inputfiles.length ; index++){
		
			var inputfile = inputfiles[index];
			
	
			if(inputfile.value == ""){
				
				showmess("请选择文件或者删除没有选中文件的行记录!");
				return false;
			}else{
			
					var fileType = inputfile.value.substring(inputfile.value.lastIndexOf(".")+1,inputfile.value.length);

					if(fileType != "zip" && fileType != "rar"){
					
					showmess("请上传压缩文件,文件大小不能超过20M");
					return false;
					}

					parent.showHideFun();
					parent.changeShowMessage("数据处理中,请等候......");
			}
		}
		
			
	}
	
	
	return true;
}

</script> 
</body>
</html>